<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<style>
		
	</style>
	<body>
		<div id="app">
			<cpn @itemclick='btnClick'></cpn>
		</div>
		
		<template id="cpn">
			<div>
				<button v-for="item in cts" @click="btnClick(item)">{{item.name}}</button>
			</div>
		</template>
		
		<script src="../js/vue.js"></script>
		<script>
			const cpn = {
				template: '#cpn',
				data(){
					return {
						cts:[
							{id: 'aaa', name: '热门推荐'},
							{id: 'bbb', name: '手机数码'},
							{id: 'ccc', name: '家用家电'},
							{id: 'ddd', name: '电脑办公'}
						]
					}
				},
				methods: {
					btnClick(item){
						// console.log(item);
						// 向父组件 发射事件: 自定义事件
						this.$emit('itemclick',item)
						
					}
				}
			}
			
			const app = new Vue({
				el: '#app',
				data: {
					info: {
						name: 'roc',
						age: 18,
						height: 180
					}
				},
				components:{
					cpn
				},
				methods:{
					btnClick(item){
						console.log('btnClick',item)
					}
				}
			})
		</script>
	</body>
</html>